package com.atguigu.lease.admin.service.impl;

import com.atguigu.lease.admin.service.SystemLoginService;
import com.atguigu.lease.model.vo.CaptchaVo;
import com.wf.captcha.GifCaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class SystemLoginServiceImpl implements SystemLoginService {


    @Autowired
   StringRedisTemplate stringRedisTemplate;



    @Override
    public CaptchaVo getCaptcha() {
        //1.生成验证码
        GifCaptcha gifCaptcha = new GifCaptcha(100, 40, 4);
        //2.将验证码 存到redis中，并分配唯一的键

        String uuid = UUID.randomUUID().toString().replace("-", "");
        stringRedisTemplate.opsForValue().set("stgy:admin:" +uuid,gifCaptcha.text());

        //3.封装vo对象响应
        CaptchaVo captchaVo = new CaptchaVo();
        captchaVo.setKey(uuid);
        captchaVo.setImage(gifCaptcha.toBase64());
        return captchaVo;


    }
}
